package cn.edu.scau.cmi.chensicheng.client;

import java.util.ArrayList;

import cn.edu.scau.cmi.chensicheng.multiton.Marshal;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class MultitonClient extends Application {

	private ArrayList<String> marshalNames = new ArrayList<String>() {
		{
			add("朱德"); 
			add("彭德怀");
			add("林彪");
			add("刘伯承");
			add("贺龙");
			add("陈毅");
			add("罗荣桓");
			add("徐向前");
			add("聂荣臻");
			add("叶剑英");
			add("未知");
		}
	};
	int index = 0;

	@Override
	public void start(Stage primaryStage) {
		Text createText = new Text();
		Button createButton = new Button("一键添加元帅");
		createButton.setOnAction(e -> {
			if (Marshal.addInstance(marshalNames.get(index))) {
				createText.setText("添加" + marshalNames.get(index) + "元帅成功！");
				index++;
			} else {
				createText.setText("添加失败，人数已满10人！");
			}
		});
		Text printText = new Text();
		Button printButton = new Button("输出所有元帅");
		printButton.setOnAction(e -> {
			printText.setText(Marshal.print());
		});
		Button clearButton = new Button("清空信息");
		clearButton.setOnAction(e -> {
			createText.setText("");
			printText.setText("");
			Marshal.clear();
			index = 0;
		});
		VBox vBox = new VBox(20, createButton, printButton, clearButton, createText, printText);
		vBox.setAlignment(Pos.CENTER);
		Scene scene = new Scene(vBox, 300, 600);
		primaryStage.setScene(scene);
		primaryStage.show();
	}

	public static void main(String[] args) {
		launch(args);
	}
}
